package labox.innovation.gameserver.network.serverpackets;

import labox.innovation.config.Config;
import labox.innovation.gameserver.model.L2ItemInstance;
import labox.innovation.gameserver.model.actor.instance.FuzePcInstance;

/**
 * ���׿�ʼ
 * ��� �ͻ��˷��Ϳ��Խ��׵���Ʒ�б�
 *  PcInstance �е�  startTrade()��Ϣ�е��� ��С����˫�������ʹ���Ϣ
 * @author zjj
 *
 */
public final class TradeStart extends L2GameServerPacket {
	private static final String _S__74_TRADESTART = "[S] 0x74 TradeStart";

	private FuzePcInstance _activeChar;

	private L2ItemInstance[] _itemList; //��ҿ��Խ��׵� ��Ʒ�б� ���͸�ͻ���

	public TradeStart(FuzePcInstance player) {
		_activeChar = player;
		_itemList = _activeChar.getInventory().getAvailableItems(true, (_activeChar.isGM() && Config.GM_TRADE_RESTRICTED_ITEMS));
	}

	@Override
	protected final void writeImpl() {
		if (_activeChar.getActiveTradeList() == null || _activeChar.getActiveTradeList().getPartner() == null)
			return;

		writeByte(L2GameServerPacket.PTL_TRADESTART);
		writeLong(_activeChar.getActiveTradeList().getPartner().getObjectId());
		//writeD((_activeChar != null || _activeChar.getTransactionRequester() != null)? _activeChar.getTransactionRequester().getObjectId() : 0);

		writeByte(_itemList.length);
		for (L2ItemInstance item : _itemList) {
			//			writeByte(item.getItem().getType1()); // item type1
			writeLong(item.getObjectId());
			writeString(item.getItem().getName());
			writeInt(item.getItemId());
			writeByte(item.getItem().getItemIconId());
			writeInt((int) item.getCount());
			//			writeByte(item.getItem().getType2());	// item type2
			//			writeByte(item.getCustomType2());

		}
	}

	/* (non-Javadoc)
	 * @see labox.innovation.gameserver.serverpackets.ServerBasePacket#getType()
	 */
	@Override
	public String getType() {
		return _S__74_TRADESTART;
	}
}
